<template>
	<view class="gy-news-list">
		<view class="gy-news-item" v-for="(item,index) in list" :key="index" @click.stop="toDetailsFn(item)">
			<view class="gy-news-details">
				<view class="gy-news-title">{{ item.title }}</view>
			<!-- 	<view v-if="props.infoType && props.infoType === 'user'" class="gy-news-info-user">
					<com-avatar :src="item.avatar" :size="40" :radius="20" />
					<view class="gy-news-user-name">{{ item.doctorName || "互联网医院" }}</view>
					<view class="gy-news-user-title">{{ item.positionName }}</view>
				</view>
				-->
				<view  class="gy-news-info">
					<view>浏览 <text>{{ item.readNum }}</text></view>
					<view>点赞 <text>{{ item.likeNum }}</text></view>
					<view><text>{{ proxy.utils.date.format(item.createTime, "yyyy.MM.dd") }}</text></view>
				</view> 
			</view>
			<view v-if="props.infoType && props.infoType === 'user'" class="gy-news-cover">
				<com-image style="width: 190rpx;" :src="item.coverImg" mode="" :height="140" />
				<view class="gy-news-cover-tag" :style="'background:'+item.backColor+ ';'">{{ item.tagName }}</view>
				<!-- <view v-if="item.tag === 2" class="gy-news-cover-tag" style="customBackColor">{{item.tagName}}</view> -->
				<view v-if="item.type === 2" class="gy-news-cover-play">
					<com-icon name="gy_icon_play" color="#ffffff" :size="36" />
				</view>
			</view>
			<view v-else class="gy-news-cover">
				<com-image style="width: 190rpx;" :src="item.coverImg" mode="" :height="140" />
				<view v-if="item.type === 1 && item.classId === 1" class="gy-news-cover-tag primary">{{item.className}}
				</view>
				<view v-if="item.type === 1 && item.classId === 2" class="gy-news-cover-tag warning">{{item.className}}
				</view>
				<view v-if="item.type === 2" class="gy-news-cover-play">
					<com-icon name="gy_icon_play" color="#ffffff" :size="36" />
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import {
		getCurrentInstance
	} from 'vue';

	const { proxy } : any = getCurrentInstance();

	const props = defineProps({
		list: {
			type: Array,
			default: () => []
		},
		infoType: {
			type: String
		}
	});

	function toDetailsFn(item : any) {
		proxy.utils.uni.route.go("/pages-system/news/details?id=" + item.id);
	}
</script>

<script lang="ts">
	export default {
		options: {
			multipleSlots: true,
			styleIsolation: 'shared',
			addGlobalClass: true,
			virtualHost: true
		}
	}
</script>

<style lang="scss" scoped>
	.gy-news-list {
		.gy-news-item {
			@include flex-between-center;
			margin: 0 var(--gy-gap) var(--gy-gap) var(--gy-gap);

			.gy-news-details {
				flex: 1;
				height: 140rpx;
				@include flex-between;
				flex-direction: column;
				padding-right: 20rpx;

				.gy-news-title {
					color: var(--gy-text-color-primary);
					font-size: 30rpx;
					@include text-ellipsis(2);
				}

				.gy-news-info {
					@include flex-start-center;
					font-weight: 400;
					color: var(--gy-text-color-secondary);
					font-size: var(--gy-font-size-small);

					view+view {
						margin-left: 20rpx;
					}

					text {
						font-size: var(--gy-font-size-base);
					}
				}

				.gy-news-info-user {
					@include flex-start-end;
					font-weight: 400;
					color: var(--gy-text-color-secondary);
					font-size: var(--gy-font-size-base);

					:deep(.gy-avatar) {
						display: block;
					}

					.gy-news-user-name {
						margin-left: 20rpx;
						color: var(--gy-text-color-primary);
					}

					.gy-news-user-title {
						margin-left: 20rpx;
					}
				}
			}

			.gy-news-cover {
				width: 190rpx;
				height: 140rpx;
				position: relative;
				border-radius: var(--gy-border-radius-large);
				overflow: hidden;

				.gy-news-cover-tag {
					position: absolute;
					top: 0;
					right: 0;
					z-index: 2;
					width: 100rpx;
					height: 36rpx;
					@include flex-center-center;
					border-bottom-left-radius: var(--gy-border-radius-large);
					font-size: 20rpx;
					color: #ffffff;
				}

				.gy-news-cover-tag.primary {
					background-color: rgba(222, 144, 55, 0.7);
				}

				.gy-news-cover-tag.warning {
					background-color: rgba(87, 149, 255, 0.7);
				}

				.gy-news-cover-play {
					position: absolute;
					top: 0;
					left: 0;
					z-index: 1;
					width: 100%;
					height: 100%;
					background-color: rgba(0, 0, 0, 0.3);
					@include flex-center-center;
				}
			}
		}

		.gy-news-item+.gy-news-item {
			margin: var(--gy-gap);
			padding-top: var(--gy-gap);
			border-top: 1rpx solid var(--gy-card-line-color);
		}
	}
</style>
